<%@page import="myJDBC.lowLevel.Objects"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
<%@include file="smallJsps/styles.jsp" %>
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@include file="smallJsps/bootstrapInclude.jsp" %>
</head>
<body>	
	<%@include file="smallJsps/logoutButton.jsp" %>
	<%@include file="smallJsps/checkAdmin.jsp" %>
	<div class="row-fluid">
		<div class="span6 offset2">
<%
	int countryId;int countryFrst=-1;
	if(request.getParameter("country")!=null)
		countryId=Integer.parseInt(request.getParameter("country"));
	else
		countryId=-1;
		
	int cityId;int cityFrst=-1;
	if(request.getParameter("city")!=null)
		cityId=Integer.parseInt(request.getParameter("city"));
	else
		cityId=-1;	
		
	int districtId;int districtFrst=-1;
	if(request.getParameter("district")!=null)
		districtId=Integer.parseInt(request.getParameter("district"));
	else
		districtId=-1;
		
	int streetId;int streetFrst=-1;
	if(request.getParameter("street")!=null)
		streetId=Integer.parseInt(request.getParameter("street"));
	else
		streetId=-1;
		
	int houseId;int houseFrst=-1;
	if(request.getParameter("house")!=null)
		houseId=Integer.parseInt(request.getParameter("house"));
	else
		houseId=-1;
		
	int porchId;int porchFrst=-1;
	if(request.getParameter("porch")!=null)
		porchId=Integer.parseInt(request.getParameter("porch"));
	else
		porchId=-1;			
	String fio="";
	if(request.getParameter("fio")!=null)
		fio=request.getParameter("fio");
 %>
<form action="createCustomer" name="form2"  method="GET">
	<label>FIO<br><input type="text" name="fio" value="<%=fio%>" onchange="submit()"></label>
</form>
<form action="createCustomer" name="form" method="GET">
		<label>country<br><select name="country" onchange="submit()">
			<%{
				ArrayList<String> countryes=new ArrayList<String>();
				countryes=Objects.returnObjInfoWithObjTypeID(45);
				if(countryes.size()!=0)				
					countryFrst=Integer.parseInt(countryes.get(0));
				for(int i=0;i<countryes.size();i+=2){
					out.print("<option value=\"" +countryes.get(i)+ "\" ");
					if(Integer.parseInt(countryes.get(i))==countryId)
						out.print("selected");
					out.print("> " +countryes.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=45>create new</a></label>
	<input type="hidden" value="<%=fio%>" name="fio">
</form>	
<form action="createCustomer" name="form" method="GET">
		<label>city<br><select name="city" onchange="submit()">
			<%
			if(countryId==-1){
				countryId=countryFrst;
			}
			if(countryId!=-1){
				ArrayList<String> cityes=new ArrayList<String>();
				for(int i: Objects.returnChildrens(countryId)){
					cityes.add(String.valueOf(i));
					cityes.add(Objects.returnObjInfo(i).get(0));
				}
				if(cityes.size()!=0)
					cityFrst=Integer.parseInt(cityes.get(0));
				for(int i=0;i<cityes.size();i+=2){
					out.print("<option value=\"" +cityes.get(i)+ "\" ");
					if(Integer.parseInt(cityes.get(i))==cityId)
						out.print("selected");
					out.print("> " +cityes.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=46&par=<%=countryId%>>create new</a></label>	
	<input type="hidden" value="<%=fio%>" name="fio">
	<input type="hidden" value="<%=countryId%>" name="country">
</form>	

<form action="createCustomer" name="form" method="GET">
		<label>district<br><select name="district" onchange="submit()">
			<%
			if(cityId==-1){
				cityId=cityFrst;
			}
			if(cityId!=-1){
				ArrayList<String> districts=new ArrayList<String>();
				for(int i: Objects.returnChildrens(cityId)){
					districts.add(String.valueOf(i));
					districts.add(Objects.returnObjInfo(i).get(0));
				}
				if(districts.size()!=0)
					districtFrst=Integer.parseInt(districts.get(0));
				for(int i=0;i<districts.size();i+=2){
					out.print("<option value=\"" +districts.get(i)+ "\" ");
					if(Integer.parseInt(districts.get(i))==districtId)
						out.print("selected");
					out.print("> " +districts.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=47&par=<%=cityId%>>create new</a></label>	
	<input type="hidden" value="<%=fio%>" name="fio">
	<input type="hidden" value="<%=countryId%>" name="country">
	<input type="hidden" value="<%=cityId%>" name="city">
</form>	

<form action="createCustomer" name="form" method="GET">
		<label>street<br><select name="street" onchange="submit()">
			<%
			if(districtId==-1){
				districtId=districtFrst;
			}
			if(districtId!=0){
				ArrayList<String> streets=new ArrayList<String>();
				for(int i: Objects.returnChildrens(districtId)){
					streets.add(String.valueOf(i));
					streets.add(Objects.returnObjInfo(i).get(0));
				}
				if(streets.size()!=0)
					streetFrst=Integer.parseInt(streets.get(0));
				for(int i=0;i<streets.size();i+=2){
					out.print("<option value=\"" +streets.get(i)+ "\" ");
					if(Integer.parseInt(streets.get(i))==streetId)
						out.print("selected");
					out.print("> " +streets.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=48&par=<%=districtId%>>create new</a></label>
	<input type="hidden" value="<%=fio%>" name="fio">	
	<input type="hidden" value="<%=countryId%>" name="country">
	<input type="hidden" value="<%=cityId%>" name="city">
	<input type="hidden" value="<%=districtId%>" name="district">	
</form>	

<form action="createCustomer" name="form" method="GET">
		<label>house<br><select name="house" onchange="submit()">
			<%
			if(streetId==-1){
				streetId=streetFrst;
			}
			if(streetId!=-1){
				ArrayList<String> houses=new ArrayList<String>();
				for(int i: Objects.returnChildrens(streetId)){
					houses.add(String.valueOf(i));
					houses.add(Objects.returnObjInfo(i).get(0));
				}
				if(houses.size()!=0)
					houseFrst=Integer.parseInt(houses.get(0));
				for(int i=0;i<houses.size();i+=2){
					out.print("<option value=\"" +houses.get(i)+ "\" ");
					if(Integer.parseInt(houses.get(i))==houseId)
						out.print("selected");
					out.print("> " +houses.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=49&par=<%=streetId%>>create new</a></label>	
	<input type="hidden" value="<%=fio%>" name="fio">
	<input type="hidden" value="<%=countryId%>" name="country">
	<input type="hidden" value="<%=cityId%>" name="city">
	<input type="hidden" value="<%=districtId%>" name="district">	
	<input type="hidden" value="<%=streetId%>" name="street">	
</form>	

<form action="createCustomer" name="form" method="GET">
		<label>porch<br><select name="porch" onchange="submit()">
			<%
			if(houseId==-1){
				houseId=houseFrst;
			}
			if(houseId!=-1){
				ArrayList<String> porchs=new ArrayList<String>();
				for(int i: Objects.returnChildrens(houseId)){
					porchs.add(String.valueOf(i));
					porchs.add(Objects.returnObjInfo(i).get(0));
				}
				if(porchs.size()!=0)
					porchFrst=Integer.parseInt(porchs.get(0));
				for(int i=0;i<porchs.size();i+=2){
					out.print("<option value=\"" +porchs.get(i)+ "\" ");
					if(Integer.parseInt(porchs.get(i))==porchId)
						out.print("selected");
					out.print("> " +porchs.get(i+1)+"</option>");
				}
				}
			%>
	</select><a href=createObject2?sel=50&par=<%=houseId%>>create new</a></label>	
	<input type="hidden" value="<%=fio%>" name="fio">
	<input type="hidden" value="<%=countryId%>" name="country">
	<input type="hidden" value="<%=cityId%>" name="city">
	<input type="hidden" value="<%=districtId%>" name="district">	
	<input type="hidden" value="<%=streetId%>" name="street">	
	<input type="hidden" value="<%=houseId%>" name="house">	
</form>	

<form action="InitOrder" name="form2"  method="GET">
	<input type="hidden" value="<%=fio%>" name="fio">
	<input type="hidden" value="<%=countryId%>" name="country">
	<input type="hidden" value="<%=cityId%>" name="city">
	<input type="hidden" value="<%=districtId%>" name="district">	
	<input type="hidden" value="<%=streetId%>" name="street">	
	<input type="hidden" value="<%=houseId%>" name="house">	
	<%
	if(porchId==-1)
		porchId=porchFrst;
	 %>
	<input type="hidden" value="<%=porchId%>" name="porch">	
	<label>apartment<br><input type="text" name="apartment"></label>
	<input class="btn btn-large btn-primary" type="submit" value="Create client">
</form>

</div>
</div>
</body>
</html>